#!/bin/sh
#
# Run a simple backup 
#   then restore it.
#
TestName="weird-files2-test"
JobName=weird-files2
. scripts/functions

if test ! -d weird-files ; then
   echo " "
   echo "weird files not configured. Test not run."
   exit 0
fi
scripts/cleanup
scripts/copy-test-confs
change_jobname NightlySave $JobName

rm -rf weird-files2
cp -Rp weird-files weird-files2
echo "${cwd}/weird-files2" >${cwd}/tmp/file-list
cd weird-files2
#perl socket.pl     # we no longer restore sockets
cd ..

start_test

${bin}/btestls weird-files2 | sort >${cwd}/tmp/original

cat <<END_OF_DATA >tmp/bconcmds
@$out /dev/null
messages
@$out tmp/log1.out
label storage=File volume=TestVolume001
run job=$JobName yes
wait
messages
@output
quit
END_OF_DATA

run_susan
check_for_zombie_jobs storage=File
#
# Now mess up the a hard link, and a soft link
#
cd weird-files2
rm -f hard-file2
ln hard-file3 hard-file2
rm -f soft-file2
ln -s soft-file3 soft-file2
cd ${cwd}
cat <<END_OF_DATA >tmp/bconcmds
@$out /dev/null
messages
@#
@# now do a restore
@#
@$out tmp/log2.out
restore where= storage=File
5
unmark *
mark *
done
yes
wait
messages
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=File
stop_susan

${bin}/btestls weird-files2 | sort >${cwd}/tmp/restored

check_two_logs
diff -u ${cwd}/tmp/original ${cwd}/tmp/restored 2>&1 >/dev/null
#diff -u ${cwd}/tmp/original ${cwd}/tmp/restored
dstat=$?
if test $dstat -ne 0; then
   diff -u ${cwd}/tmp/original ${cwd}/tmp/restored
fi

end_test
